package com.moduls.interfaceFunction.controller;

import com.moduls.interfaceFunction.core.Result;
import com.moduls.interfaceFunction.core.SqlMapper;
import net.sf.json.JSONObject;
import org.apache.ibatis.session.SqlSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.IOException;
import java.sql.Date;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.*;

public class MyAction {
	private final Logger logger = LoggerFactory.getLogger(MyAction.class);
	@Autowired
	public SqlSession sqlSessions;
	private JSONObject obj_vars;
	public Result results=new Result();
	public basictool basictool = new basictool();
	public JSONObject getObj_vars() {
		return obj_vars;
	}

	public void setObj_vars(JSONObject obj_vars) {
		this.obj_vars = obj_vars;
	}
	

	// 接口功能：服务商首页(ok)
	public void service_user_home_page_get() throws SQLException {
		Map<String, Object> result = new HashMap<String, Object>();
		 SqlMapper sqlMapper=new SqlMapper(sqlSessions);
		JSONObject obj_vars = getObj_vars();
		String loc_lng = obj_vars.optString("loc_lng"); // 首页定位  经度
		String loc_lat = obj_vars.optString("loc_lat"); // 首页定位 维度
		 //首页行业显示
		List<Map<String, Object>> maps = sqlMapper.selectList("select set_title as title,set_img as img,set_val as value from p_set where set_type=202");
		result.put("aboutUs",maps);
		sqlMapper.selectList("SELECT a.* FROM " +
				"(SELECT *, " +
				"ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(("+loc_lat+" * PI() / 180 - loc_lat * PI() / 180) / 2),2) + COS(\"+loc_lat+\" * PI() / 180) * COS(loc_lat * PI() / 180) * POW(SIN(("+loc_lng+" * PI() / 180 - loc_lng * PI() / 180) / 2),2))) * 1000) AS juli " +
				"FROM s_provider) as a where a.juli < 30000 ORDER BY a.juli ASC ");
		result.put("top_banner", get_banner(200));//顶部banner图
         result.put("centre_banner", get_banner(201));//中间banner图
         result.put("recommend_news", sqlMapper.selectList("select * from m_news"));//热门|推荐
         result.put("recommend_user", sqlMapper.selectList("select a.pid,a.work_avatar,b.srv_title,c.catalog_name,a.experience from s_provider a,s_service b,m_catalog c WHERE a.pid in (SELECT task_id from m_task_recommend WHERE rec_type=1) and a.pid=b.pid  and b.catalog_id=c.catalog_id"));//优质|服务
		result.put("task_list", sqlMapper.selectList("SELECT IFNULL(a.avatar,'') avatar,IFNULL(a.nick_name,'') nick_name,b.task_desc from p_user a,m_task b where a.uid=b.uid ORDER BY b.create_time desc LIMIT 10"));//任务列表
		result.put("provider_list", sqlMapper.selectList("SELECT a.pid,b.srv_id,work_avatar,experience,CONCAT(left(real_name,1),'师傅') as real_name,c.catalog_name from s_provider a ,s_service b,m_catalog c where a.is_forbid=0 and a.pid=b.pid and b.catalog_id=c.catalog_id ORDER BY a.create_time desc LIMIT 10"));//服务之星
         results.setResult(result);// 输出：列表数据
         results.setStatus(1);// 输出：状态1成功 0失败
         results.setMessage("ok");// 输出：提示信息
	}
	//左侧-用户信息
	public  void provider_detail(){
		Map<String, Object> result = new HashMap<String, Object>();
		SqlMapper sqlMapper=new SqlMapper(sqlSessions);
		JSONObject obj_vars = getObj_vars();
		String userid = obj_vars.optString("userid");//登录服务商id
		Map<String, Object> map = sqlMapper.selectOne("SELECT * from s_provider ");
		result.put("userInfo",map);
		results.setResult(result);// 输出：列表数据
		results.setStatus(1);// 输出：状态1成功 0失败
		results.setMessage("ok");// 输出：提示信息

	}
	//首页-地图-任务详情 task content
	public  void  task_detail(){
		Map<String, Object> result = new HashMap<String, Object>();
		SqlMapper sqlMapper=new SqlMapper(sqlSessions);
		JSONObject obj_vars = getObj_vars();
		String taskid = obj_vars.optString("taskid");
		String userid = obj_vars.optString("userid");
		Integer ifcollect = 0;
		Integer ifCanRobTask = 1;
		//基本信息
		Map<String, Object> map = sqlMapper.selectOne("SELECT t.*,c.catalog_name from m_task t " +
				"LEFT JOIN m_catalog c on c.catalog_id = t.catalog_id" + taskid);
		Map<String, String> district_id = getAreaDetailById(map.get("district_id").toString());
		String area = district_id.get("province")+district_id.get("city")+district_id.get("area");
		map.put("serviceplace",area);
		//查询用户评分
		Map<String, Object> map1 = sqlMapper.selectOne("SELECT avg(e.evl_level) as star from s_evaluation e  " +
				"LEFT JOIN m_order o on e.oid = o.oid  " +
				"LEFT JOIN p_user u on u.uid = o.uid  " +
				"where u.uid =(SELECT uid from m_task where task_id = "+taskid+" ) ");
		map.put("star",map1.get("star").toString());//用户所有评论均值

		//图片
		List<Map<String, Object>> list = sqlMapper.selectList("SELECT content from p_content where business_type = 100 and business_id = " + taskid);
		//查询是否已经订阅
		List<Map<String, Object>> maps1 = sqlMapper.selectList("SELECT COUNT(*) from s_collect where task_id =" + taskid + " and pid = " + userid);
		if (maps1.size()>0){
			ifcollect = 1;
		}
		//查询已形成订单个数  判断是否能够下单
		List<Map<String, Object>> maps2 = sqlMapper.selectList("SELECT * from m_order where pid =" + userid + " and `status`!= '已完成' and is_history = 0");
		if(maps2.size()>=3){
			ifCanRobTask = 0;
		}
		result.put("ifCanRobTask",ifCanRobTask);//是否能抢单 1是 0 否
		result.put("ifcollect",ifcollect);//是否已经收藏 1是  0 否
		result.put("detail",map);
		result.put("imgs",list);
		results.setResult(result);// 输出：列表数据
		results.setStatus(1);// 输出：状态1成功 0失败
		results.setMessage("ok");// 输出：提示信息
	}

	//任务详情-评价列表
	public void get_content_list(){
		Map<String, Object> result = new HashMap<String, Object>();
		SqlMapper sqlMapper=new SqlMapper(sqlSessions);
		JSONObject obj_vars = getObj_vars();
		String userid = obj_vars.optString("userid");//发布任务用户id
		String taskid = obj_vars.optString("taskid");//跳过来前的taskid
		String pagenum = obj_vars.optString("pagenum");//当前页数
		int pagesize = 12;
		int limitStart = (Integer.parseInt(pagenum) - 1) * pagesize;
		//查询用户评分及评价个数
	/*	sqlMapper.selectOne("se")
		Map<String, Object> map1 = sqlMapper.selectOne("SELECT avg(e.evl_level) as star,COUNT(*) as count  from s_evaluation e  " +
				"LEFT JOIN m_order o on e.oid = o.oid  " +
				"LEFT JOIN p_user u on u.uid = o.uid  " +
				"where u.uid =(SELECT uid from m_task where task_id = "+taskid+" ) ");*/
		//查询所有评价
		List<Map<String, Object>> maps = sqlMapper.selectList("SELECT e.evl_level,e.evl_content,date_format(e.create_time,'%Y-%m-%d %H:%i:%s') as create_time,p.real_name,p.work_avatar from s_evaluation e " +
				"LEFT JOIN m_order o on e.oid = o.oid " +
				"LEFT JOIN p_user u on u.uid = o.uid " +
				"LEFT JOIN s_provider p on p.pid = e.pid " +
				"where u.uid = (SELECT uid from m_task where task_id = " + taskid + ") limit "+limitStart+","+pagenum+"");
		Map<String, Object> map = sqlMapper.selectOne("SELECT evl_level,evl_num from p_user where uid =(SELECT uid from m_task where task_id = " + taskid + ")");
		result.put("contentList",maps);
		result.put("evg",map);
		results.setResult(result);
		results.setStatus(1);// 输出：状态1成功 0失败
		results.setMessage("ok");// 输出：提示信息
	}

	//首页-地图-任务详情-收藏
	public void collect_task(){
		Map<String, Object> result = new HashMap<String, Object>();
		SqlMapper sqlMapper=new SqlMapper(sqlSessions);
		JSONObject obj_vars = getObj_vars();
		String taskid = obj_vars.optString("taskid"); //任务id
		String userid = obj_vars.optString("userid"); // 服务商id
		//insertOrUpdate 入collect表
		HashMap<String, String> map = new HashMap<>();
		map.put("pid",userid);
		map.put("task_id",taskid);
		//Integer res = -1;
		try {
			Integer res = sqlMapper.insert_or_update("s_collect", map, "");

			if (res>-1){
				results.setStatus(1);// 输出：状态1成功 0失败
				results.setMessage("ok");// 输出：提示信息
			}else {
				results.setStatus(0);// 输出：状态1成功 0失败
				results.setMessage("收藏失败");// 输出：提示信息
			}
		}catch (Exception e){
			logger.error("collect_task  insert_or_update  error ",e);
		}



	}

	//首页-地图-任务详情-抢单
	public  void rob_task(){
		Map<String, Object> result = new HashMap<String, Object>();
		SqlMapper sqlMapper=new SqlMapper(sqlSessions);
		JSONObject obj_vars = getObj_vars();
		String taskid = obj_vars.optString("taskid"); //任务id
		String task_titile = obj_vars.optString("task_titile"); //任务标题
		String userid = obj_vars.optString("userid");//服务商id
		//String userid_task = obj_vars.optString("userid_task");
		//将当前任务转化为订单 状态为待确认

		HashMap<String, String> map = new HashMap<>();
		//从打赏表中获取信息
		Map<String, Object> one = sqlMapper.selectOne("SELECT user_id,reward_no,amount from p_reward WHERE reward_type=1 and business_id = " + taskid);

		map.put("uid",sqlMapper.selectOne("select * from m_task where taskid ="+taskid).get("uid").toString());
		map.put("status","待支付");
		map.put("order_no",one.get("reward_no").toString());
		map.put("order_amount",one.get("amount").toString());
		map.put("pid",userid);
		map.put("task_id",taskid);
		map.put("point_id","0");
		map.put("is_history","0");
		map.put("history_type","0");
		try {

			int m_order = sqlMapper.insert_or_update("m_order", map,"");
			int update = sqlMapper.update("update m_task set is_trans = (case is_trans when 0 then 1 end)");

			if (m_order>-1&&update>-1){
				//通知客户单被抢
				sqlMapper.insert("imsert in to (p_message msg_type,msg_title,msg_content) values("+101+",'订单已被抢','订单："+task_titile+"已被抢，请等待师傅电话')");
				results.setStatus(1);// 输出：状态1成功 0失败
				results.setMessage("ok");// 输出：提示信息
			}else {
				results.setStatus(0);// 输出：状态1成功 0失败
				results.setMessage("抢单失败");// 输出：提示信息
			}
		}catch (Exception e){
			logger.error("rob order error");
		}

	}


	//我要抢单-服务列表
	public void task_list(){
		Map<String, Object> result = new HashMap<String, Object>();
		SqlMapper sqlMapper=new SqlMapper(sqlSessions);
		JSONObject obj_vars = getObj_vars();
		String area = obj_vars.optString("area"); //区域id
		String lat = obj_vars.optString("lat"); //纬度
		String lng = obj_vars.optString("lng"); //经度
		String pagenum = obj_vars.optString("pagenum"); //分页
		String ordertype = obj_vars.optString("ordertype"); //筛选优先 1 服务质量从高到低 2 服务质量从低到高 3 离我最近
		int pagesize = 12;
		int limitStart = (Integer.parseInt(pagenum) - 1) * pagesize;

		//没有筛选时显示推荐内容
		if ("".equals(area)&& "".equals(ordertype)) {
			List<Map<String, Object>> maps = sqlMapper.selectList("(SELECT s.* from " +
					"(SELECT t.*,u.evl_level,r.rec_id,ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN((" + lat + " * PI() / 180 - lat * PI() / 180) / 2),2) + COS(" + lat + " * PI() / 180) * COS(lat * PI() / 180) * POW(SIN((" + lng + " * PI() / 180 - lng * PI() / 180) / 2),2))) * 1000) AS juli," +
					"  c.catalog_name " +
					"from m_task t " +
					"LEFT JOIN m_task_recommend r on t.task_id = r.task_id " +
					"LEFT JOIN p_areas a on a.id = t.district_id " +
					"LEFT JOIN m_catalog c on c.catalog_id = t.catalog_id LEFT JOIN p_user u on u.uid = t.uid " +
					"ORDER BY juli asc) as s where s.is_trans = 0 and s.rec_id is  not  null  " +
					")UNION (SELECT b.* from " +
					"(SELECT t.*,u.evl_level,r.rec_id,ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN((" + lat + " * PI() / 180 - lat * PI() / 180) / 2),2) + COS(" + lat + " * PI() / 180) * COS(lat * PI() / 180) * POW(SIN((" + lng + " * PI() / 180 - lng * PI() / 180) / 2),2))) * 1000) AS juli," +
					"  c.catalog_name " +
					"from m_task t " +
					"LEFT JOIN m_task_recommend r on t.task_id = r.task_id " +
					"LEFT JOIN p_areas a on a.id = t.district_id " +
					"LEFT JOIN m_catalog c on c.catalog_id = t.catalog_id LEFT JOIN p_user u on u.uid = t.uid" +
					"ORDER BY juli asc) as b where   b.is_trans = 0 and b.rec_id is null " +
					") LIMIT " + limitStart + "," + pagesize + "");
			for (Map<String,Object> map:
				 maps) {
				Map<String, String> district_id = getAreaDetailById(map.get("district_id").toString());
				String city1 = district_id.get("city");
				map.put("city",city1);
			}
			result.put("taskList",maps);

		}else{
			String orderby = "";
			if("1".equals(ordertype)){
				orderby = " ORDER BY b.evl_level desc ";
			}if("2".equals(ordertype)){
				orderby = " ORDER BY b.evl_level asc ";
			}
			List<Map<String, Object>> maps = sqlMapper.selectList("SELECT b.* from" +
					"(SELECT t.*,r.rec_id,ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN((" + lat + " * PI() / 180 - lat * PI() / 180) / 2),2) + COS(" + lat + " * PI() / 180) * COS(lat * PI() / 180) * POW(SIN((" + lng + " * PI() / 180 - lng * PI() / 180) / 2),2))) * 1000) AS juli," +
					"  a.`name` as area,c.catalog_name " +
					"from m_task t " +
					"LEFT JOIN m_task_recommend r on t.task_id = r.task_id " +
					"LEFT JOIN p_areas a on a.id = t.district_id " +
					"LEFT JOIN m_catalog c on c.catalog_id = t.catalog_id LEFT JOIN p_user u on u.uid = t.uid" +
					"ORDER BY juli asc) as b where b.district_id = "+area+"  and  b.is_trans = 0 "+orderby+" limit "+limitStart+","+pagesize+" ");
			for (Map<String,Object> map:
					maps) {
				Map<String, String> district_id = getAreaDetailById(map.get("district_id").toString());
				String city1 = district_id.get("city");
				map.put("city",city1);
			}
			result.put("taskList",maps);
		}
		results.setResult(result);// 输出：列表数据
		results.setStatus(1);// 输出：状态1成功 0失败
		results.setMessage("ok");// 输出：提示信息

	}

	//订单-列表(服务商)
	public void order_list(){
		Map<String, Object> result = new HashMap<String, Object>();
		SqlMapper sqlMapper=new SqlMapper(sqlSessions);
		JSONObject obj_vars = getObj_vars();
		String status = obj_vars.optString("status"); //订单状态
		String pid = obj_vars.optString("userid"); //服务用户id
		String pagenum = obj_vars.optString("pagenum"); //分页
		int pagesize = 12;
		int limitStart = (Integer.parseInt(pagenum) - 1) * pagesize;
		if ("待确认".equals(status)){
			List<Map<String, Object>> maps = sqlMapper.selectList("SELECT t.task_id,t.task_title,u.real_name,c.catalog_name,o.`status` from m_order o " +
					"LEFT JOIN m_task t on o.task_id = t.task_id " +
					"LEFT JOIN m_catalog c on c.catalog_id = t.catalog_id " +
					"LEFT JOIN p_user u on u.uid = t.uid " +
					"where o.task_id != 0 and o.`status` = '待确认' and o.pid = "+pid+" limit "+limitStart+","+pagesize+"");
			result.put("orderList",maps);
		}
		if ("进行中".equals(status)){
			List<Map<String, Object>> maps = sqlMapper.selectList("(SELECT  t.task_id,o.point_id,t.task_title as title,u.real_name,c.catalog_name,o.`status` from m_order o  " +
					"LEFT JOIN m_task t on o.task_id = t.task_id " +
					"LEFT JOIN m_catalog c on c.catalog_id = t.catalog_id " +
					"LEFT JOIN p_user u on u.uid = t.uid " +
					"where o.task_id != 0 and o.`status` = '进行中')union( " +
					"SELECT o.task_id,o.point_id,s.srv_title as title,p.real_name,c.catalog_name,o.`status` from m_order o  " +
					"LEFT JOIN s_service s ON o.srv_id = s.srv_id " +
					"LEFT JOIN s_provider p on p.pid = s.pid " +
					"LEFT JOIN m_catalog c on c.catalog_id = s.catalog_id " +
					"where o.task_id = 0 and o.`status` = '进行中' " +
					")  limit "+limitStart+","+pagesize+"");
			result.put("orderList",maps);
		}
		if ("已完成".equals(status)){
			List<Map<String, Object>> maps = sqlMapper.selectList("(SELECT  t.task_id,o.point_id,t.task_title as title,u.real_name,c.catalog_name,o.`status` from m_order o  " +
					"LEFT JOIN m_task t on o.task_id = t.task_id " +
					"LEFT JOIN m_catalog c on c.catalog_id = t.catalog_id " +
					"LEFT JOIN p_user u on u.uid = t.uid " +
					"where o.task_id != 0 and o.`status` = '已完成')union( " +
					"SELECT o.task_id,o.point_id,s.srv_title as title,p.real_name,c.catalog_name,o.`status` from m_order o  " +
					"LEFT JOIN s_service s ON o.srv_id = s.srv_id " +
					"LEFT JOIN s_provider p on p.pid = s.pid " +
					"LEFT JOIN m_catalog c on c.catalog_id = s.catalog_id " +
					"where o.task_id = 0 and o.`status` = '已完成' " +
					")  limit "+limitStart+","+pagesize+"");
			result.put("orderList",maps);
		}
		results.setResult(result);// 输出：列表数据
		results.setStatus(1);// 输出：状态1成功 0失败
		results.setMessage("ok");// 输出：提示信息


	}

/*	//订单-详情    与个人的相同
	public void service_order_detail(){
		Map<String, Object> result = new HashMap<String, Object>();
		SqlMapper sqlMapper=new SqlMapper(sqlSessions);
		JSONObject obj_vars = getObj_vars();
		String orderid = obj_vars.optString("orderid"); //订单id
		String ifpoint = obj_vars.optString("ifpoint"); //是否点单 1是 0 否 空为否
		String pid = obj_vars.optString("userid"); //服务用户id
		if ("".equals(ifpoint)||"0".equals(ifpoint)){
			//抢单详情
			Map<String, Object> map = sqlMapper.selectOne("SELECT t.*,c.catalog_name,date_format(o.create_time,'%Y-%m-%d %H:%i:%s') as create_time,o.order_no,date_format(o.finish_time,'%Y-%m-%d %H:%i:%s') as finish_time from m_order o " +
					"LEFT JOIN m_task t on o.task_id = t.task_id " +
					"LEFT JOIN m_catalog c on c.catalog_id = t.catalog_id " +
					"WHERE o.is_history != 1 and o.oid = " + orderid);
			results.setResult(map);
			results.setStatus(1);// 输出：状态1成功 0失败
			results.setMessage("ok");// 输出：提示信息
		}else{
			//点单详情


		}

	}*/

	//订单-进行中提醒完成
	public void notify_finished(){
		Map<String, Object> result = new HashMap<String, Object>();
		SqlMapper sqlMapper=new SqlMapper(sqlSessions);
		JSONObject obj_vars = getObj_vars();
		String oid = obj_vars.optString("oid"); //订单id
		String userid = obj_vars.optString("userid"); //服务商id
		String name = sqlMapper.selectOne("select real_name from s_provider where pid = "+userid).get("real_name").toString();
		int insert = sqlMapper.insert("imsert in to (p_message msg_type,msg_title,msg_content) values(" + 102 + ",'请确定订单完成','师傅" + name + "提醒你完成订单')");
		if (insert>-1){
			results.setStatus(1);// 输出：状态1成功 0失败
			results.setMessage("ok");// 输出：提示信息
		}else{
			results.setStatus(0);// 输出：状态1成功 0失败
			results.setMessage("操作失败");// 输出：提示信息
		}
	}

	//订单-进行中-评价
	public void order_appraise(){
		Map<String, Object> result = new HashMap<String, Object>();
		SqlMapper sqlMapper=new SqlMapper(sqlSessions);
		JSONObject obj_vars = getObj_vars();
		String oid = obj_vars.optString("oid"); //订单id
		String userid = obj_vars.optString("userid"); //服务商id
		String evl_content = obj_vars.optString("evl_content"); //评价内容
		String attitude_level = obj_vars.optString("attitude_level"); //沟通态度级别
		String desc_level = obj_vars.optString("desc_level"); //	需求描述级别
		String pay_level = obj_vars.optString("pay_level"); //费用支付级别
		String ontime_level = obj_vars.optString("ontime_level"); //	时效性级别
		String cooperation_level = obj_vars.optString("cooperation_level"); //	本次合作的满意级别
		Integer evl_level = (Integer.parseInt(attitude_level)+Integer.parseInt(desc_level)+Integer.parseInt(pay_level)+Integer.parseInt(ontime_level)+Integer.parseInt(cooperation_level))/5;
		Map<String, String> map = new HashMap<String, String>();
		map.put("oid",oid);
		map.put("pid",userid);
		map.put("evl_content",evl_content);
		map.put("attitude_level",attitude_level);
		map.put("desc_level",desc_level);
		map.put("pay_level",pay_level);
		map.put("ontime_level",ontime_level);
		map.put("cooperation_level",cooperation_level);
		map.put("evl_level",evl_level.toString());
		try {
			int s_evaluation = sqlMapper.insert_or_update("s_evaluation", map, "");
			if (s_evaluation>-1){
				results.setStatus(1);// 输出：状态1成功 0失败
				results.setMessage("评价成功");// 输出：提示信息
			}else{
				results.setStatus(0);// 输出：状态1成功 0失败
				results.setMessage("评价失败");// 输出：提示信息
			}
		}catch (Exception e){
			logger.error(" insert s_evaluation error ");
		}


	}

	//订单-已完成-删除订单
	public void delete_order(){
		Map<String, Object> result = new HashMap<String, Object>();
		SqlMapper sqlMapper=new SqlMapper(sqlSessions);
		JSONObject obj_vars = getObj_vars();
		String oid = obj_vars.optString("oid"); //订单id
		Map<String, String> map = new HashMap<String, String>();
		map.put("is_history","1");
		map.put("history_type","2");
		try {
			int m_order = sqlMapper.insert_or_update("m_order", map, "oid = "+oid);
			if (m_order>-1){
				results.setStatus(1);// 输出：状态1成功 0失败
				results.setMessage("ok");// 输出：提示信息
			}else{
				results.setStatus(0);// 输出：状态1成功 0失败
				results.setMessage("删除失败");// 输出：提示信息
			}
		}catch (Exception e){
			logger.error("update order error ");
		}


	}





	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	public List<Map<String, Object>> get_banner(int ADV_TYPE){
		//轮播图公共方法
		 SqlMapper sqlMapper=new SqlMapper(sqlSessions);
		List<Map<String, Object>> list=  sqlMapper.selectList("select  adv_id,adv_img,adv_type,adv_data,date_format(create_time,'%Y-%m-%d %H:%i:%s') as create_time  from P_ADV where ADV_TYPE="+ADV_TYPE);
		return list;
	}
	public List<Map<String, Object>> get_setData(int SET_TYPE){
		//设置数据
		 SqlMapper sqlMapper=new SqlMapper(sqlSessions);
		List<Map<String, Object>> list=  sqlMapper.selectList("select  set_id,set_type,set_title,set_img,set_val from P_SET  where set_type="+SET_TYPE);
		return list;
	}
	public String get_time(Date time){
		//时间转string方法
		 SimpleDateFormat format =  new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return  format.format(time);
	}
	// 返回订单号后面的部分/唯一值
	public String public_getordercode(String userid) {
		Random rand = new Random();
		int randNum = rand.nextInt(8999) + 1000;
		return System.currentTimeMillis() + Integer.toString(randNum) + userid;
	}
	public Map<String,String> getAreaDetailById(String id) { //传入areaid  返回 map
		SqlMapper sqlMapper = new SqlMapper(sqlSessions);
		HashMap<String, String> result = new HashMap<>();
		Map<String, Object> stringObjectMap = sqlMapper.selectOne("SELECT * from p_areas where id = " + id);
		String spid = stringObjectMap.get("spid").toString();

		if ("0".equals(spid)) {
			//省级
			String province = stringObjectMap.get("name").toString();
			result.put("province", province);
			return result;
		} else {
			String[] split = spid.split("\\|");
			if (split.length == 1) {
				String city = stringObjectMap.get("name").toString();
				//市级
				Map<String, Object> map = sqlMapper.selectOne("SELECT * from p_areas where id = " + split[0]);
				String area = map.get("name").toString();
				result.put("city", city);
				result.put("area", area);
				return result;
			}
			if (split.length == 2) {
				String area = stringObjectMap.get("name").toString();
				//区级
				Map<String, Object> map = sqlMapper.selectOne("SELECT * from p_areas where id = " + split[0]);
				Map<String, Object> map1 = sqlMapper.selectOne("SELECT * from p_areas where id = " + split[1]);
				String province = map.get("name").toString();
				String city = map1.get("name").toString();
				result.put("province", province);
				result.put("city", city);
				result.put("area", area);
				return result;
			}

		}
		return  null;
	}

}
